package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduExamRecordDTO;
import com.zenith.edu.po.vo.EduExamRecordVO;
import com.zenith.edu.service.EduExamRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/exam-record")
@Tag(name = "考试记录管理", description = "考试记录管理接口")
public class EduExamRecordController {
    
    @Autowired
    private EduExamRecordService eduExamRecordService;
    
    @SecurePostMapping(value = "createExamRecord",roles = "ROLE_ADMIN",permission = "examRecord:create")
    @Operation(summary = "创建考试记录")
    public Result<EduExamRecordVO> createExamRecord(@RequestBody EduExamRecordDTO dto) {
        EduExamRecordVO examRecordVO = eduExamRecordService.createExamRecord(dto);
        return Result.success(examRecordVO);
    }
    
    @SecurePostMapping(value = "getExamRecordById",roles = "ROLE_ADMIN",permission = "examRecord:get")
    @Operation(summary = "根据ID获取考试记录详情")
    public Result<EduExamRecordVO> getExamRecordById(@PathVariable Long id) {
        EduExamRecordVO examRecordVO = eduExamRecordService.getExamRecordById(id);
        if (examRecordVO == null) {
            return Result.fail("考试记录不存在");
        }
        return Result.success(examRecordVO);
    }
    
    @SecurePostMapping(value = "updateExamRecord",roles = "ROLE_ADMIN",permission = "examRecord:update")
    @Operation(summary = "更新考试记录信息")
    public Result<EduExamRecordVO> updateExamRecord(@RequestBody EduExamRecordDTO dto) {
        EduExamRecordVO examRecordVO = eduExamRecordService.updateExamRecord(dto);
        return Result.success(examRecordVO);
    }
    
    @SecurePostMapping(value = "deleteExamRecord",roles = "ROLE_ADMIN",permission = "examRecord:delete")
    @Operation(summary = "删除指定考试记录")
    public Result<Void> deleteExamRecord(@PathVariable Long id) {
        boolean result = eduExamRecordService.deleteExamRecord(id);
        if (!result) {
            return Result.fail("考试记录删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "getExamRecordList",roles = "ROLE_ADMIN",permission = "examRecord:read")
    @Operation(summary = "获取考试记录列表")
    public Result<List<EduExamRecordVO>> getExamRecordList() {
        List<EduExamRecordVO> examRecordList = eduExamRecordService.getExamRecordList();
        return Result.success(examRecordList);
    }
}